`ruleset.rpart` <-
function(model) {
	# Check if model inherits rpart.
	if (!inherits(model, "rpart")) stop("Not a legitimate rpart tree")

	# Get some information.
	frm      = model$frame
	names    = row.names(frm)
	ylevels  = attr(model, "ylevels")
	ds.size  = model$frame[1,]$n
	iterator = 1

	# Result goes here.
	result = list()
	
	# Save each leaf node as a rule list.
	for (i in 1:nrow(frm))
	{
		if (frm[i,1] == "<leaf>")
		{
			# Add the whole path to leaf-node.
			result[iterator] = path.rpart(model, nodes=as.numeric(names[i]), print.it=FALSE)
			
			# Rule result as 1st field in a rule.
			result[[iterator]][1] = ylevels[frm[i,]$yval]

			iterator = iterator+1
		}
	}

	# Parse each rule in result.
	res = list()
	for(j in 1:length(result)) {
		res[[as.character(j)]] = parse.rule(result[[j]]) 
	}
	return(res)
}

